package com.bana.fvs.protocol;

import com.bana.fvs.model.Controller;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;

/**
 * 查询控制器基本信息
 * 开始地址，结束地址，巡检间隔时间
 */
public class QueryControllerTextConfig {

    public int getId()
    {
        return 0x37;
    }

    public byte[] toBuffer(int kzqbsm)
    {
        byte[] buffer=new byte[4];
        buffer[0]=(byte)0x81;
        buffer[1]=(byte)kzqbsm;
        buffer[2]=(byte)getId();
        buffer[3]=(byte)0xff;
        return buffer;
    }

    public Controller toModel(byte[] buffer) throws IOException {
        ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
        DataInputStream dis = new DataInputStream(bais);
        dis.skipBytes(1);
        dis.skipBytes(1);
        dis.skipBytes(1);
        Controller controller=new Controller();
        controller.setLxbh(dis.readByte());
        byte b5=dis.readByte();
        //第1位为1时触发一次手动
        controller.setCfsd((b5&0x01)==0?0:1);
        controller.setSfgs((b5&0x02)==0?0:1);
        controller.setDscf((b5&0x04)==0?0:1);
        controller.setQxcf((b5&0x08)==0?0:1);
        controller.setWzmk2((b5&0x10)==0?0:1);
        controller.setWzmk1((b5&0x20)==0?0:1);
        controller.setWdgz((b5&0x40)==0?0:1);

        controller.setGs_Lddj(dis.readByte());
        controller.setGs_Sspl(dis.readByte());
        controller.setGs_Zkb(dis.readByte());
        return controller;
    }
}
